//
//  HomeViewController.swift
//  SwiftSign
//
//  Created by continue on 2021/4/26.
//

import UIKit
import RxSwift

class HomeViewController: ViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    override func bindViewModel() {
        guard let viewModel = viewModel as? HomeViewModel else { return }
        let ready = Observable.just(())
        let output = viewModel.transform(input: HomeViewModel.Input(ready: ready))
        output.loginSelected.drive(onNext: { viewModel in
            self.navigator.show(segue: .loginMenu(viewModel: viewModel), sender: self, transition: .modal)
        }).disposed(by: rx.disposeBag)
        
        viewModel.parsedError.asObservable().bind(to: error).disposed(by: rx.disposeBag)
        error.subscribe(onNext: { [weak self] (error) in
            var title = ""
            switch error {
            case .serverError(let response):
                title = response.message ?? ""
            }
            self?.view.makeToast(title)
        }).disposed(by: rx.disposeBag)
        
        LogError("Identifier for the file logging destination Error")
        LogWarn("Identifier for the file logging destination Warn")
        LogInfo("Identifier for the file logging destination Info")
        LogDebug("Identifier for the file logging destination Debug")
    
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
